********************************************************************************
* Purpose: Imams data analysis - scaleup Eid ul Azha 2020 
* Sub-file: HTE mystery shoppers 
********************************************************************************

	****************************************************************************
	* Load data
	****************************************************************************

	use			"${imamsurvey}/merged_scaleup.dta" , clear 
	
	keep		if consent_statement==1											// Restrict the sample here to people who responded in the baseline / T calls
																				

	****************************************************************************
	* Estimates
	****************************************************************************\
	
	estimates	clear 

	foreach		j in trustgovt ///
					 pti anyulema anymadrasa {
		
	cap			drop *hte* 
	gen			hte = `j' 
	
	local		k = 0 
	
	foreach		i in $msoutcomes {
	
				* Gen interaction terms
				
				cap			gen treatment_any_hte1 = (treatment_any==1) * (hte ==1)
				cap			gen treatment_any_hte0 = (treatment_any==1) * (hte==0)
				cap			gen treatment_sec_hte1 = treatment_secular * (hte==1)
				cap			gen treatment_comb_hte1 = treatment_combined * (hte==1)
				cap			gen treatment_sec_hte0 = treatment_secular * (hte==0)
				cap			gen treatment_comb_hte0 = treatment_combined * (hte==0)
				
				label		variable treatment_any_hte1 "T x ``j'1'"
				label		variable treatment_any_hte0 "T x ``j'0'"

				label		variable treatment_sec_hte1 "Secular T x ``j'1'"
				label		variable treatment_sec_hte0 "Secular T x ``j'0'"
				label		variable treatment_comb_hte1 "Secular + religious T x ``j'1'"
				label		variable treatment_comb_hte0 "Secular + religious T x ``j'0'"
				
				
				* Counter
				
				local		k = `k' + 1
				
				* Two groups
				
				reg 		`i' treatment_any_hte0 ///
								treatment_any_hte1 ///
								`j'  ///
								, robust 					
				
				est			sto c`j'`k'
				
				test		treatment_any_hte0 = treatment_any_hte1 
				local		pvalc`i' = string(round(r(p), .01))				
				estadd 		scalar pvaldiff = r(p) 

				sum			`j' if e(sample) 
				estadd		scalar prophte = round(r(mean) , .01) 				

				sum			`i' if e(sample) & treatment_any==0 
				estadd		scalar mean = round(r(mean) , .01) 				

				sum			`i' if e(sample)==1 & control==1 & `j'==0
				estadd		scalar mean0 = round(r(mean), .01) 
				
				sum			`i' if e(sample)==1 & control==1 & `j'==1 
				estadd		scalar mean1 = round(r(mean), .01) 
				
				estadd		local htevar ``j'1'
				
				global		estimatesc $estimatesc c`j'`k'

				
				
				
				* 4 groups
				
				reg 		`i' treatment_sec_hte0 ///
								treatment_comb_hte0 ///
								treatment_sec_hte1 ///
								treatment_comb_hte1 ///
								`j'  ///
								, robust 					
				
				est			sto d`j'`k'
				
				test		treatment_sec_hte0 = treatment_comb_hte0 
				local		pd`i'1 = string(round(r(p), .01))		
				estadd		scalar pval1 = r(p) 
				
				test		treatment_sec_hte1 = treatment_comb_hte1
				local		pd`i'2 = string(round(r(p), .01))		
				estadd		scalar pval2 = r(p) 
				
				test		treatment_sec_hte1 = treatment_sec_hte0
				local		pd`i'3 = string(round(r(p), .01))		
				estadd		scalar pval3 = r(p) 
				
				test		treatment_comb_hte1 = treatment_comb_hte0
				local		pd`i'4 = string(round(r(p), .01))		
				estadd		scalar pval4 = r(p) 
								
				estadd		local htevar ``j'1'

				sum			`j' if e(sample) 
				estadd		scalar prophte = round(r(mean) , .01) 				

				sum			`i' if e(sample)==1 & control==1 & `j'==0
				estadd		scalar mean0 = round(r(mean), .01) 
				
				sum			`i' if e(sample)==1 & control==1 & `j'==1 
				estadd		scalar mean1 = round(r(mean), .01) 
				
				global		estimatesd $estimatesc d`j'`k' 
				
				
				
				
	
	}

	
				
	}

	
	
	****************************************************************************
	* Mechanism tables with specific subsets of results - multiple HTEs 
	****************************************************************************
	
	label		variable treatment_any_hte1 "$\beta_1$: T $\times$ (interaction variable=1)"
	label		variable treatment_any_hte0 "$\beta_2$: T $\times$ (interaction variable=0)"

	label		variable treatment_sec_hte0 "$\beta_1$: Secular T $\times$ (interaction variable=0)"
	label		variable treatment_comb_hte0 "$\beta_2$: Secular + religious T $\times$ (interaction variable=0)"
	label		variable treatment_sec_hte1 "$\beta_3$: Secular T $\times$ (interaction variable=1)"
	label		variable treatment_comb_hte1 "$\beta_4$: Secular + religious T $\times$ (interaction variable=1)"
	
	

	* BL measures of alignment with secular & religious authorities 

	esttab		ctrustgovt1 cpti1 canymadrasa1 canyulema1 ///
					using "${texrct}/scaleup_ms_hte_polit_mech.tex" , ///
					replace star(* .1 ** .05 *** .01) se t(3) b(3) label ///
					scalars( ///
					"htevar Interaction variable" ///
					"pvaldiff P-value $\beta_1$ = $\beta_2$" ///
					"mean0 Control mean Y for interaction variable = 0" ///
					"mean1 Control mean Y for interaction variable = 1" ///
					"prophte Proportion of sample with interaction variable = 1") ///
					keep(treatment*) ///
					nonotes fragment booktabs ///
					mgroups("Index - advice to mystery shopper" , pattern(1 0 0 0 0) ///
					prefix(\multicolumn{@span}{c}{) suffix(}) span 			     ///
					erepeat(\cmidrule(lr){@span})) ///
					nodepvars nomtitles substitute(\_ _)
	
	esttab		dtrustgovt1 dpti1 danymadrasa1 danyulema1  ///
					using "${texrct}/scaleup_ms_hte_polit_mech_arms.tex" , ///
					replace star(* .1 ** .05 *** .01) se t(3) b(3) label ///
					scalars( ///
					"htevar Interaction variable" ///
					"pval1 P-value $\beta_1$ = $\beta_2$" ///
					"pval2 P-value $\beta_3$ = $\beta_4$" ///
					"pval3 P-value $\beta_1$ = $\beta_3$" ///
					"pval4 P-value $\beta_2$ = $\beta_4$" ///
					"mean0 Control mean Y for interaction variable = 0" ///
					"mean1 Control mean Y for interaction variable = 1" ///
					"prophte Proportion of sample with interaction variable = 1") ///
					keep(treatment*) ///
					nonotes fragment booktabs ///
					mgroups("Index - advice to mystery shopper" , pattern(1 0 0 0 0) ///
					prefix(\multicolumn{@span}{c}{) suffix(}) span 			     ///
					erepeat(\cmidrule(lr){@span})) ///
					nodepvars nomtitles substitute(\_ _)

